<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .msg {
            margin-left: 43px;
            color: #cbcbcb;
        }
        
        .right {
            color: green;
            border: 1px solid green;
        }
        
        .wrong {
            color: red;
            border: 1px solid red;
        }
    </style>
</head>

<body>
    <div>
        密码：<input type="password" />
        <div class="msg">
            <img src="" />
            <span>6-16位字母</span>
        </div>
    </div>

    <script>
        var oInput = document.querySelector("input");
        var oImg = document.querySelector("img");
        var oSpan = document.querySelector("span");


        //绑定 光标离开事件
        oInput.onblur = function() {
            //获取 input框中的数据
            var value = this.value;
            var l = value.length;
            if (l >= 6 && l <= 16) {
                oImg.src = "./img/right.png";
                oSpan.innerHTML = "您输入的密码格式是正确的";
                oSpan.style.color = "green";
                oInput.className = "right";


            } else if (l == 0) {
                oInput.style.color = "#cbcbcb";
                oImg.src = "";
                oSpan.style.zIndex = "10";
                // oSpan.inneHTML = "";
                oSpan.innerHTML = "6-16位字母";
                oSpan.style.color = "";
                oInput.className = "";

            } else {
                oImg.src = "./img/wrong.png";

                oSpan.innerHTML = "您输入的密码格式是错误的";
                oSpan.style.color = "red";
                oInput.className = "wrong";
            }

            console.log(oSpan.innerHTML);
        }


        //作业3：当 文本框中的数据为空的时候，需要重置效果
    </script>
</body>

</html>